<%--
	飲食店向け受注システム
	メイン画面
	チーム名：Wild_Card
	作成：南橋　由起子
	作成日：2014/09/24
---%>
<%@page import="wildcard.servlet.LoginBean" import="java.util.ArrayList"
	import="wildcard.database.DBAccess"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>メイン画面</title>
</head>
<body>
	<%
		String title = (String) session.getAttribute("title");
		String target = (String) session.getAttribute("target");
	%>
	<table>
		<tr>
			<td colspan="390"><font size="18" color="F92500"><%=title%></font></td>
			<td bgcolor="#32CCB6"><form action="maintenance_menu.jsp"
					method="post">
					<button type="submit" style="WIDTH: 120px; HEIGHT: 45px">
						<font style="font-size: 20px" color="FFFF00">メインメニューに戻る</font>
					</button>
				</form></td>
		</tr>
	</table>
	<br>

	<%
		// 出力リストの取得
		ArrayList<ArrayList<String>> resultList = (ArrayList<ArrayList<String>>) request
				.getAttribute("result");

		// ターゲットの値を取得
		String sqlCode = null;
		int codeBase = 12;
		if ("TABLES".equals(target)) {
			codeBase = 20;
		}

		String select = "SQL" + codeBase;
		session.setAttribute("select", select);
	%>

	<form method="POST" action=masteredit>
		<input type="hidden" name="select" value="<%=select%>">
		<table border="1">
			<%
				ArrayList<String> columnNames = resultList.get(0);
				for (int row = 0; row < resultList.size(); row++) {
					ArrayList<String> record = resultList.get(row);
					String idValue = record.get(0);
			%>
			<tr>
				<%
					for (int column = 0; column < record.size(); column++) {
							String data = record.get(column);
							String name = columnNames.get(column) + idValue;
				%>
				<%
					if (column == 0) {
				%>
				<td colspan="10"><input type="hidden"
					name="<%=columnNames.get(column)%>" value="<%=data%>" /><%=data%></td>
				<%
					} else if (row == 0) {
				%>
				<td align="center"><%=data%></td>
				<%
					} else {
				%>
				<td><input type="text" name=<%=name%> value="<%=data%>"
					size="15" maxlength="15"></td>
				<%
					}
				%>
				<%
					}
				%>
			</tr>
			<%
				}
			%>
		</table>

		<table>
			<%-- 編集画面の操作 --%>
			<tr>
				<td>
					<%
						sqlCode = "SQL" + (codeBase + 2);
					%>
					<BUTTON type="submit" name="sql" value="<%=sqlCode%>">更新</BUTTON>
				</td>
				<td colspan="20"></td>
				<%
					sqlCode = "SQL" + (codeBase + 3);
				%>
				<td><input type="text" name="values" size="5" maxlength="5"></td>
				<td>
					<BUTTON type="submit" name="sql" value="<%=sqlCode%>">削除</BUTTON>
				</td>
			</tr>
		</table>
	</form>

	<br>

	<%-- 新規入力フォーム --%>
	<form method="POST" action=masteredit>
		<input type="hidden" name="select" value="<%=select%>">
		<table border="1">
			<tr>
				<%
					ArrayList<String> labels = resultList.get(0);
					for (String label : labels) {
						if ("ID".equals(label))
							continue;
				%>
				<td><%=label%></td>
				<%
					}

					sqlCode = "SQL" + (codeBase + 1);
				%>
				<td rowspan="2"><BUTTON type="submit" name="sql"
						value="<%=sqlCode%>">登録</BUTTON></td>
			</tr>
			<tr>
				<%
					for (String label : labels) {
				%>
				<%
					if ("ID".equals(label))
							continue;
				%>
				<td><input type="text" name="values" size="15" maxlength="15"></td>
				<%
					}
				%>
			</tr>
		</table>
	</form>

	<%-- 消費税処理 --%>
	<%
		// ユーザIDの取得
		LoginBean loginBean = (LoginBean) session.getAttribute("LoginUser");
		String dbId = loginBean.getLoginId().substring(0, 2);
		String dbPassword = loginBean.getPassword();

		// SQL文の取得
		ArrayList<String> parameters = new ArrayList<String>();
		parameters.add("SQL9");
		resultList = DBAccess.executeSelect(dbId, dbPassword,
				DBAccess.SQL_SELECT_COMMAND, parameters);
		String sql = resultList.get(1).get(0);
		resultList = DBAccess.executeSelect(dbId, dbPassword, sql, null);
		String tax = resultList.get(1).get(0);
	%>
	<br>

	<form method="POST" action=masteredit>
		<table border="1">
			<tr>
				<td>消費税</td>

				<td><input type="text" name="values" value="<%=tax%>" size="2"
					maxlength="2"></td>
				<td><BUTTON type="submit" name="sql" value="SQL10">変更</BUTTON></td>
			</tr>
		</table>
	</form>

</body>
</html>